/*
 *  myangio.h
 *  fix
 *
 *  Created by wumin on 8/2/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */



#include "../Matrix.h"


class VesselCell{
public:
 int cIndex;
 double i;
 double j;
 int cConnection;
 
 char cFate;//'S'=Stable,'T'=Sprout Tip, 'D'= Die and Silent, 'P'=Stalk cell which proliferate
 double cReceptor;
 double cRadius;
 double cPermeability;
 double cPericytes;
 
 bool cSetPressure;
 int cConnectIndex[6];
//Matrix cConnectIndex;

 VesselCell* pNextVesselCell;
 VesselCell* pPreviousVesselCell;
VesselCell();
~VesselCell();
};




class CellVesselStructure{
private:

/*
void InitializeVesselMatrix(bool VesselResume);

void InitializeVesselMatrix(bool VesselResume);
void InitializeVesselListInOrder(bool VesselResume);
void InjectPosition(int innumbers, int outnumbers, bool randomized);



void GrowSprout(void);
void GrowSprout(Matrix& Shuffle);
void WSSTAFBranchByProbInterval(void);
void WSSTAFBranchByProbInterval(Matrix& Shuffle);

void VesselAdaption(void);
void UpdateHematocrit(void);
void MindeUpdateHematocrit(void);
void UpdateViscosity(void);
void UpdateWallShearStress(void);
void UpdateRadius(void);
void UpdateConductivity(void);

void GetVesselPressureAndFlow(void);
*/


public:


void InitializeCellTime(bool Resume);
void InitializeCellListCircle(bool VesselResume);
void InitializeCellList(bool VesselResume);
bool SaveVesselList(void);
void GenerateMatrix(void);
void ShuffleFate(Matrix& Signal);
void String_Interact(Matrix& Signal);
void Grow(Matrix& Signal);
void GrowSprout(Matrix& Signal);
void Grow_zero(Matrix& Signal);
void Grow_One(Matrix& Signal);
void Grow_Deprecate(Matrix& Signal);
VesselCell* FindCell(int Index);
VesselCell* FindCell(int i, int j);
int CellListLength;
int SproutNumber;

Matrix Distance;
Matrix pRadius;
Matrix pPermeability;
Matrix pConduct;
Matrix pFlow;
Matrix pPericytes;
Matrix Indicator;


VesselCell* pFirstVesselCell;
VesselCell* pLastVesselCell;


/*

void VesselInitialization( bool VesselResume );
void UpdateVesselSystem(void);
void UpdateVesselSystemSteadyState(void);
void UpdateVesselSystemSteadyStateShuffle(Matrix& Shuffle);
void ChainAngioPressureUpdate(int MaxIterations, double Tolerance);
void ChainAngioPressureUpdateTwoDirection(int MaxIterations, double Tolerance);
void ChainAngioPressureUpdateTwoDirectionAdaptive(int MaxIterations, double Tolerance);
void InterAngioPressureUpdate(int MaxIterations, double Tolerance);

double PTUpdate(Matrix& CoeffecientX, Matrix& CoeffecientY, Matrix& Variable,int i,int j);
void TransOutPut(void);
void RegenerateHem(void);

void GetRadiusValue(void);
void SteadyStateHematocrit(void);
void GetHaematocritValue(void);
bool CheckTAF( double Tolerance);
bool SaveVesselList(void);
*/

//void PutArteryandSprout();
CellVesselStructure();
~CellVesselStructure();
};

bool Connected(VesselCell* a, VesselCell* b);
void Connect(VesselCell* a, VesselCell* b);
void DisConnect(VesselCell* a, VesselCell* b);
//bool TestConnect(VesselCell* a, VesselCell* b);
void CompeteFate(VesselCell* a, VesselCell* b, Matrix& Signal, char Win, char Lose, char Fair);


int min_Round(double input);

/************************hualidefeigexian********************/

double AngioSORUpdate( Matrix& Solution, Matrix& ConductX, Matrix& ConductY, Matrix& BloodVesselIndicatorX, Matrix& BloodVesselIndicatorY, int i, int j, double MaxConduct);
class VesselPoint{
public:
 int i;
 int j;
 bool AmIArtery;
 bool AmIVenous;

VesselPoint* pNextVesselPoint;
VesselPoint* pPreviousVesselPoint;
VesselPoint();
~VesselPoint();

};

class VesselStructure{
private:

void InitializeTime(bool Resume);
void InitializeVesselMatrix(bool VesselResume);
void InitializeVesselListInOrder(bool VesselResume);
void InjectPosition(int innumbers, int outnumbers, bool randomized);



void GrowSprout(void);
void GrowSprout(Matrix& Shuffle);
void WSSTAFBranchByProbInterval(void);
void WSSTAFBranchByProbInterval(Matrix& Shuffle);

void VesselAdaption(void);
void UpdateHematocrit(void);
void MindeUpdateHematocrit(void);
void UpdateViscosity(void);
void UpdateWallShearStress(void);
void UpdateRadius(void);
void UpdateConductivity(void);

void GetVesselPressureAndFlow(void);



public:
VesselPoint* pFirstVesselPoint;
VesselPoint* pLastVesselPoint;
double NodeLength;
int SproutNumber;
int VesselListLength;
void ArteryPosition(void);
void VesselInitialization( bool VesselResume );
void UpdateVesselSystem(void);
void UpdateVesselSystemSteadyState(void);
void UpdateVesselSystemSteadyStateShuffle(Matrix& Shuffle);
void ChainAngioPressureUpdate(int MaxIterations, double Tolerance);
void ChainAngioPressureUpdateTwoDirection(int MaxIterations, double Tolerance);
void ChainAngioPressureUpdateTwoDirectionAdaptive(int MaxIterations, double Tolerance);
void InterAngioPressureUpdate(int MaxIterations, double Tolerance);

double PTUpdate(Matrix& CoeffecientX, Matrix& CoeffecientY, Matrix& Variable,int i,int j);
void TransOutPut(void);
void RegenerateHem(void);

void GetRadiusValue(void);
void SteadyStateHematocrit(void);
void GetHaematocritValue(void);
bool CheckTAF( double Tolerance);
bool SaveVesselList(void);


//void PutArteryandSprout();
VesselStructure();
~VesselStructure();
};


void AngioUpdateMDE(void);
void AngioUpdateECM(void);
void AngioUpdateTAF(void);
void GetMaxTAF(void);
double min_abs(double);
double FluidPressureUpdateBoundaryPoint( Matrix& Diffusion,  Matrix& BloodNodePressure, Matrix& Solution,   int i, int j);
double FluidPressureUpdateBoundaryPointD( Matrix& Diffusion,  Matrix& BloodNodePressure, Matrix& Solution,   int i, int j);
double AngioFluidPressureUpdate( Matrix& Diffusion,  Matrix& BloodNodePressure, Matrix& Solution,   int i, int j);
double AngioLymSORUpdate( Matrix& Permeability, Matrix& InterPressure, Matrix& Solution, Matrix& ConductX, Matrix& ConductY, Matrix& BloodVesselIndicatorX, Matrix& BloodVesselIndicatorY,  int i, int j, double MaxConduct);
